using System;
using System.Diagnostics;

namespace CL
{
    public static class CLLog
    {
        private const int TraceLevel = 1;
        private const int DebugLevel = 2;
        private const int InfoLevel = 3;
        private const int WarningLevel = 4;

        public static int OptionLogLevel = 1;

        private static ICLLog GetLog()
        {
            return CLFiber.Instance != null ? CLFiber.Instance.Log : CLLogger.Instance.Log;
        }

        public static void Debug(string msg)
        {
            if (OptionLogLevel > DebugLevel)
            {
                return;
            }

            GetLog().Debug(msg);
        }

        public static void Trace(string msg)
        {
            if (OptionLogLevel > TraceLevel)
            {
                return;
            }
            StackTrace st = new(1, true);
            GetLog().Trace($"{msg}\n{st}");
        }

        public static void Info(string msg)
        {
            if (OptionLogLevel > InfoLevel)
            {
                return;
            }
            GetLog().Info(msg);
        }

        public static void TraceInfo(string msg)
        {
            if (OptionLogLevel > InfoLevel)
            {
                return;
            }
            StackTrace st = new(1, true);
            GetLog().Trace($"{msg}\n{st}");
        }

        public static void Warning(string msg)
        {
            if (OptionLogLevel > WarningLevel)
            {
                return;
            }
            GetLog().Warning(msg);
        }

        public static void Error(string msg)
        {
            StackTrace st = new(1, true);
            GetLog().Error($"{msg}\n{st}");
        }

        public static void Error(Exception e)
        {
            GetLog().Error(e);
        }

        public static void Console(string msg)
        {
            GetLog().Debug(msg);
        }

    }
}
